package com.tianqu.tms.www.bid.controller;

import java.text.ParseException;
import java.util.Date;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.util.DateUtil;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.entity.AucManagement;

public class BidStatucCheckAjaxController extends TmsController {

	private static final String RESPONSETEXT = "responseText";
	private Logger logger = Logger.getLogger(BidStatucCheckAjaxController.class);

	@Override
	public void execute(UserContext uc) throws Exception {
		
		logger.debug(this.getClass().getName() + "#execute was called.");
		
		TxController controller = TxController.getTxController();

		// 添加事务提交异常捕获
		try {
			
			controller.begin();
			
			// 竞价管理
			AucManagement aucManage = AucManagement.getInstance();
			
			// 车辆ID
			int id = StringUtil.getint(uc.getParameter("carId"));
			
			StringBuffer sb = new StringBuffer();
				
			// 根据车辆ID取得车辆信息
			AucManagement auc = aucManage.getAucInfoById(id);

			// 车辆ID
			sb.append(StringUtil.getString(id));
			sb.append(",");

			// 车辆号
			sb.append(auc.getSerial());
			sb.append(",");
			
			// 竞价状态			sb.append(StringUtil.getString(auc.getBidStatus()));

			controller.commit();
			String responseText = sb.toString();
			uc.setAttribute(RESPONSETEXT, responseText);

		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}

		logger.debug(this.getClass().getName() + "#execute was completed.");
	}

}
